import sqlalchemy

engine = sqlalchemy.create_engine('mysql://root:longbhu1214@123.56.253.79/testdb', echo=True)

meta_data = sqlalchemy.MetaData()

person = sqlalchemy.Table(
    "person", meta_data,
    sqlalchemy.Column("id", sqlalchemy.Integer, primary_key=True),
    sqlalchemy.Column("name", sqlalchemy.String(128), unique=True, nullable=False),
    sqlalchemy.Column("time", sqlalchemy.Date, nullable=False)
)

meta_data.create_all(engine)

person_insert = person.insert() # 返回的insert插入语句

# execute() 插入语句为参数一，数据作为参数二
with engine.connect() as conn:
    result = conn.execute(person_insert,
                          [{"name": "name1", "time": "2024-1-2"},
                           {"name": "name2", "time": "2024-1-3"},
                           {"name": "name3", "time": "2024-1-4"},
                           ]
                          )
    conn.commit()
    conn.close()
